package com.sun.jdktimer;

import java.time.LocalDateTime;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleThreadPool01 {
    public static void main(String[] args) {
        ScheduledExecutorService service = Executors.newScheduledThreadPool(5);
        for (int i = 0; i < 2; i++) {
            service.scheduleAtFixedRate(new TimerTask02("task:" + i),1L,2L, TimeUnit.SECONDS);
        }
    }
}
class TimerTask02 extends TimerTask{
    private String name;

    public TimerTask02(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        try {
            System.out.println(name + "：TimerTask01正在执行....." + LocalDateTime.now());
//            Thread.sleep(1000);
            System.out.println(name + "：TimerTask01执行结束....." + LocalDateTime.now());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}